<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/common/head.jsp"%>
</head>
<body class="${cookie.bodyClass.value}">
	<div class="container body">
		<div class="main_container">
			<%@ include file="/WEB-INF/common/left.jsp"%>
			<%@ include file="/WEB-INF/common/top.jsp"%>
			<!-- page content -->
			<div class="right_col" role="main" id="main">
				<div class="x_panel">
					<div class="x_title">
						<h2>商品管理列表</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<form role="form" id="searchForm">
							<div class="container">
								<div class="row">
									<div class="col-lg-3">
										<input class="form-control input-sm" placeholder="请输入要查询的订单号" name="map['orderNumber']"/>
									</div>
									<div class="col-lg-3">
										<input class="form-control input-sm" placeholder="请输入要查询的用户名" name="map['nickName']"/>
									</div>
									<div class="col-lg-3">
										<input class="form-control input-sm" placeholder="请输入要查询的用户手机号码" name="map['cellphone']"/>
									</div>
								</div>
								<div class="row">
									<div class="col-lg-3">
										<select class="form-control input-sm" name="map['orderStatus']">
											<option value="">--订单状态--</option>
											<option value="0">待支付</option>
											<option value="1">待发货</option>
											<option value="2">待收货</option>
											<option value="3">待评价</option>
											<option value="4">交易完成</option>
											<option value="5">交易取消</option>
											<option value="6">已退单</option>
										</select>
									</div>
									<div class="col-lg-3">
										<select class="form-control input-sm" name="map['payType']">
											<option value="">--支付类型--</option>
											<option value="0">积分兑换</option>
											<option value="1">支付宝</option>
											<option value="2">微信</option>
										</select>
									</div>
									<div class="col-lg-3">
										<button type="button" class="btn btn-primary btn-sm" onclick="search();">搜索</button>
									</div>
								</div>
							</div>
						</form>
						<div class="table-responsive">
							<table id="banners" class="table table-bordered table-striped table-hover" 
							  cellspacing="0" width="100%">
								<thead>
									<tr class="mytableHead">
										<th class="myRowNumber"></th>
										<!-- <th>id</th> -->
										<th>订单编号</th>
										<th>会员名</th>
										<th>会员电话</th>
										<th>订单状态</th>
										<th>订单支付金额</th>
										<th>订单支付类型</th>
										<th>订单创建时间</th>
										<th>订单支付时间</th>
										<th>操作</th>
									</tr>
								</thead>
							</table>
						</div>
					</div>
				</div>
			</div>
			<!-- /page content -->
			<%@ include file="/WEB-INF/common/foot.jsp"%>
		</div>
	</div>
	<%@ include file="/WEB-INF/common/script.jsp"%>
	<script>
	$(function(){
		var t = $("#banners").DataTable({
		    ajax: {
		        url: ctx+'admin/order/findOrders',
		        type: 'POST',
		        data: function(d){$.extend(d,serializeObject($("#searchForm")))}
		    },
		    columns: [
		        { "data":null,"render":rowNumberRender},
		        /* { "data":'id'}, */
		        { "data":'orderNumber'},
		        { "data":'nickName'},
		        { "data":'cellphone'},
		        { "data":'orderStatus',"render":rowisStatus},
		        { "data":'payMoney'},
                { "data":'payType',"render":rowisPay},
		        { "data":'createDate',"render":rowisCreatedTime},
		        { "data":'payDate',"render":rowisPayTime},
		        { "data":'id',"render":optRender}
		    ]
		    
		});
		$("#searchForm input").keydown(function(event){
			if(event.keyCode == 13){
				search();
			}
		});
		$("#searchForm select").change(search);
	});
	
	function optRender(data, type, row, meta){
		var but = '<a class="btn btn-info btn-xs" href="javascript:view('+meta.row+')"><i class="fa fa-pencil"></i>编辑</a>';
//		but = but + '<a class="btn btn-danger btn-xs" href="javascript:deleteById('+row.bannerId+')"><i class="fa fa-remove"></i>删除</a>';
		return but;
	}
	function view(index,event){
		var row = $('#banners').DataTable().rows().data()[index];
		window.location = ctx+"admin/order/toOrderDetailPage?orderId="+row.id;
	}
	
	function rowNumberRender(data, type, row, meta) {
	    var setting = meta.settings;
	    var rowNumber = setting._iDisplayStart + (meta.row + 1);
		return rowNumber;
  	}
	
	function imageUrlRender(data, type, row, meta){
		var imageUrl=row.imageUrl;
		return "<img style='width:100px;height:50px' src='"+imgDomain+"/"+imageUrl+"'/>";
	}

	function rowisStatus(data, type, row, meta){
		var orderStatus = row.orderStatus;
		if(Number(orderStatus)==0){
		    return '待支付';
		}else if(Number(orderStatus)==1){
            return '待发货';
		}else if(Number(orderStatus)==2){
            return '待收货';
        }else if(Number(orderStatus)==3){
            return '待评价';
        }else if(Number(orderStatus)==4){
            return '交易完成';
        }else if(Number(orderStatus)==5){
            return '交易取消';
        }else if(Number(orderStatus)==6){
            return '已退单';
        }
	}

	function rowisPay(data, type, row, meta){
		var payType = row.payType;
		if(payType==''||payType==null){
			return '未支付';
		}else{
            if(Number(payType)==0){
                return '积分兑换';
            }else if(Number(payType)==1){
                return '支付宝';
            }else if(Number(payType)==2){
                return '微信';
            }
		}
	}

    function rowisCreatedTime(data, type, row, meta){
        var createDate = row.createDate;
        if(Number(createDate)>0){
            return new Date(parseInt(createDate)).format("yyyy-MM-dd hh:mm:ss");
        }else{
            return '';
		}
    }

    function rowisPayTime(data, type, row, meta){
        var payDate = row.payDate;
        if(Number(payDate)>0){
            return new Date(parseInt(payDate)).format("yyyy-MM-dd hh:mm:ss");
        }else{
            return '未支付';
        }
    }

    function search(){
		$('#banners').DataTable().ajax.reload(function(d){$.extend(d,serializeObject($("#searchForm")))}, true);
	}
	function deleteById(id){
		swal({ "title": "", "text": "确定要删除该一级分类" ,"type": "warning","showCancelButton":true},function(isConfirm){
			if(isConfirm){
				$.ajax({
					url: ctx+"admin/banner/deleteBanner?bannerId="+id+"&time="+(new Date()).getTime(),
					dataType: "json",
					success: function(result){
						if(result.status == "0"){
							search();
						}else{
							swal({title:'',text:result.msg,type:"error"});
						}
					}
				});
			}
		});
	}


    Date.prototype.format = function(format)
    {
        var o = {
            "M+" : this.getMonth()+1, //month
            "d+" : this.getDate(),    //day
            "h+" : this.getHours(),   //hour
            "m+" : this.getMinutes(), //minute
            "s+" : this.getSeconds(), //second
            "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
            "S" : this.getMilliseconds() //millisecond
        }
        if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
            (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)if(new RegExp("("+ k +")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length==1 ? o[k] :
                    ("00"+ o[k]).substr((""+ o[k]).length));
        return format;
    }

	</script>
</body>
</html>